Skip to content

Conversation

tcitworld
Copy link
Member

If a metadata property is declared with a number type but the value provided are not numeric, it just logs "A non-numeric value encountered at apps/dav/lib/Files/FileSearchBackend.php#486" instead of throwing a proper error.

Now with a proper error here we have the proper exception being thrown later: InvalidArgumentException Invalid property value for {http://nextcloud.org/ns}metadata-photos-original_date_time.

See nextcloud/photos#3187 for the actual issue in photos.

(I'm too lazy to add a specific test for this, but feel free to)

Checklist

@tcitworld tcitworld added this to the Nextcloud 33 milestone Sep 19, 2025
@tcitworld tcitworld requested a review from a team as a code owner September 19, 2025 09:58
@tcitworld tcitworld added bug 3. to review Waiting for reviews labels Sep 19, 2025
@tcitworld tcitworld requested review from icewind1991 and provokateurin and removed request for a team September 19, 2025 09:58
@tcitworld tcitworld requested a review from sorbaugh September 19, 2025 09:58
@tcitworld
Copy link
Member Author

/backport to stable32

@tcitworld
Copy link
Member Author

/backport to stable31

…perations with custom metadata

If a metadata property is declared with a number type but the value provided are not numeric, it
logs "A non-numeric value encountered at nextcloud/apps/dav/lib/Files/FileSearchBackend.php#486" instead of throwing a proper error.

Now with a proper error we have the proper exception being thrown: InvalidArgumentException Invalid
property value for {http://nextcloud.org/ns}metadata-photos-original_date_time

Signed-off-by: Thomas Citharel <[email protected]>
@tcitworld tcitworld force-pushed the handle-metadata-dav-search-error branch from 96beacb to 974cfef Compare September 19, 2025 10:04
if (is_numeric($value)) {
return 0 + $value;
}
throw new \Error('Value for numeric datatype is not numeric');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if throwing in error is better or simply ignoring it with: return 0;

Copy link
Member Author

@tcitworld tcitworld Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was indeed that it allows for the throw new \InvalidArgumentException('Invalid property value for ' . $property->name, previous: $e); exception to be thrown, so that the front-end can know something's wrong. Otherwise I might not have found about nextcloud/photos#3187

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this:

throw new \InvalidArgumentException(
    sprintf(
        'Invalid property value for %s: got "%s" (type: %s)',
        $property->name,
        is_scalar($value) ? (string)$value : gettype($value),
        gettype($value)
    )
);

and got 2 errors:
InvalidArgumentException Invalid property value for {http://owncloud.org/ns}size: got "0" (type: string)
InvalidArgumentException Invalid property value for {http://nextcloud.org/ns}metadata-photos-original_date_time: got "2024-10-09T00:00:00Z" (type: string)

I'm not sure if these errors can be safely ignored. If these warnings are not important, I'd prefer they not show up in the log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants